package com.yulintu.common;

import com.yulintu.dao.BaseBodyDaoService;
import com.yulintu.parser.AbstractBodyParser;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author caomin
 * @date 2017/10/25
 * @说明 任务调度器
 */
public class ProcessManager {

   private  static ExecutorService threadPool = Executors.newFixedThreadPool(15);
    /**
     * 处理body,与dao的线程池
     */
   private  static ExecutorService parserThread= Executors.newFixedThreadPool(2);

    //待处理队列
    private ArrayBlockingQueue<AbstractBodyParser>abstractBodyParsers=new ArrayBlockingQueue<>(15);
    //待处理队列
    private ArrayBlockingQueue<BaseBodyDaoService>baseBodyDaoServices=new ArrayBlockingQueue<>(15);



    public  ExecutorService getThreadPool() {
        return threadPool;
    }
    public  ExecutorService getParserThread() {
        return  parserThread;
    }

    private ProcessManager(){}

    private static volatile ProcessManager processManager;

    public static ProcessManager getProcessManager(){
        if (processManager==null){
            synchronized (ProcessManager.class){
                processManager=new ProcessManager();
            }
        }
        return processManager;
    }

    public ArrayBlockingQueue<AbstractBodyParser> getAbstractBodyParsers() {
        return abstractBodyParsers;
    }

    public ArrayBlockingQueue<BaseBodyDaoService> getBaseBodyDaoServices() {
        return baseBodyDaoServices;
    }
}
